package ai.people.netmon.warning.service.impl;

import ai.people.netmon.framework.domain.warning.entity.WarningAnalysisModel;
import ai.people.netmon.framework.domain.warning.vo.WarningAnalysisModelVO;
import ai.people.netmon.warning.mapper.WarningAnalysisModelMapper;
import ai.people.netmon.warning.service.WarningAnalysisModelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ligua
* @description 针对表【warning_analysis_model(预警分析模型)】的数据库操作Service实现
* @createDate 2022-07-28 17:50:38
*/
@Service
public class WarningAnalysisModelServiceImpl extends ServiceImpl<WarningAnalysisModelMapper, WarningAnalysisModel>
    implements WarningAnalysisModelService{

    //@Autowired(required = false)
    //private WarningAnalysisModelConverter warningAnalysisModelConverter;

    @Override
    public List<WarningAnalysisModelVO> accountModelList(String accountId) {
        List<WarningAnalysisModelVO> vos = Lists.newArrayList();
        //TODO 获取当前用户角色可见模型
        //TODO 获取当前主题或者账号的信源，并计算信源可见模型
        List<WarningAnalysisModel> modelList = baseMapper.selectList(new LambdaQueryWrapper<WarningAnalysisModel>().eq(WarningAnalysisModel::getDimension, 1)
                .eq(WarningAnalysisModel::getIsDelete, 0));
        return warningAnalysisModelVosConverter(vos, modelList);
    }

    private List<WarningAnalysisModelVO> warningAnalysisModelVosConverter(List<WarningAnalysisModelVO> vos, List<WarningAnalysisModel> modelList) {
        if(!CollectionUtils.isEmpty(modelList)){
            modelList.forEach(o->{
                WarningAnalysisModelVO vo = new WarningAnalysisModelVO();
                BeanUtils.copyProperties(o, vo);
                vos.add(vo);
            });
        }
        return vos;
    }

    @Override
    public List<WarningAnalysisModelVO> subjectModelList(String subjectId) {
        List<WarningAnalysisModelVO> vos = Lists.newArrayList();
        //TODO 获取当前用户角色可见模型
        //TODO 获取当前主题或者账号的信源，并计算信源可见模型
        List<WarningAnalysisModel> modelList = baseMapper.selectList(new LambdaQueryWrapper<WarningAnalysisModel>().eq(WarningAnalysisModel::getDimension, 0)
                .eq(WarningAnalysisModel::getIsDelete, 0));
        return warningAnalysisModelVosConverter(vos, modelList);
    }
}




